import { MenuCartItemType } from '@/types/menuTypes'
import { defineStore } from 'pinia'
import { ref } from 'vue'

const menuStore = defineStore('menu', () => {
  const menuItems = ref<MenuCartItemType[]>([])

  const setMenu = (items: MenuCartItemType[]) => {
    menuItems.value = items
  }

  const clearMenu = () => {
    menuItems.value = []
    localStorage.removeItem('menu_items')
  }

  return {
    menuItems,
    setMenu,
    clearMenu,
  }
}, {
  persist: {
    storage: localStorage,
    paths: ['menuItems'],
    key: 'menu_items',
  } as any
})

export default menuStore
